<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单号" prop="serialNum">
        <el-input
          v-model="queryParams.serialNum"
          placeholder="请输入单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司" prop="company">
        <el-input
          v-model="queryParams.company"
          placeholder="请输入公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>



      <el-form-item label="岗位" prop="post">
        <el-input
          v-model="queryParams.post"
          placeholder="请输入岗位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="申请人" prop="applyUserName">
        <el-input
          v-model="queryParams.applyUserName"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['module:oaEntry:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['module:oaEntry:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['module:oaEntry:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['module:oaEntry:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="oaEntryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" align="center" />
      <el-table-column label="单号" width="100" align="center" prop="serialNum" />
      <el-table-column label="公司" align="center" prop="company" />
      <el-table-column label="部门" align="center" prop="deptName" />
      <el-table-column label="职级" align="center" prop="rankName" />
      <el-table-column label="岗位" align="center" prop="post" />
      <el-table-column label="类型" align="center" prop="type" />
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="生肖" align="center" prop="animalSign" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="手机" align="center" prop="phoneNum" />
      <el-table-column label="身份证" align="center" prop="identification" />
      <el-table-column label="出生日期" align="center" prop="birthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="身高" align="center" prop="height" />
      <el-table-column label="体重" align="center" prop="weight" />
      <el-table-column label="健康情况" align="center" prop="health" />
      <el-table-column label="实习薪资" align="center" prop="internshipSalary" />
      <el-table-column label="试用时间" align="center" prop="probationTime" />
      <el-table-column label="试用期工资" align="center" prop="probationSalary" />
      <el-table-column label="转正后工资" align="center" prop="positiveSalary" />
      <el-table-column label="入职日期" align="center" prop="entryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="籍贯" align="center" prop="nativePlace" />
      <el-table-column label="民族" align="center" prop="nation" />
      <el-table-column label="学历" align="center" prop="educational" />
      <el-table-column label="政治面貌" align="center" prop="politicalStatus" />
      <el-table-column label="婚姻状况" align="center" prop="maritalStatus" />
      <el-table-column label="开户行" align="center" prop="bankDeposit" />
      <el-table-column label="银行账号" align="center" prop="bankAccountNumber" />
      <el-table-column label="现住址" align="center" prop="presentAddress" />
      <el-table-column label="紧急联系人" align="center" prop="emergencyContact" />
      <el-table-column label="所属关系" align="center" prop="ownership" />
      <el-table-column label="手机" align="center" prop="emergencyPhone" />
      <el-table-column label="商业保险" align="center" prop="commercialInsurance" />
      <el-table-column label="劳动合同签约时间" align="center" prop="laborContractSigningTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.laborContractSigningTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="劳动合同到期时间" align="center" prop="laborContractExpirationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.laborContractExpirationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="技能" align="center" prop="skill" />
      <el-table-column label="奖励证书" align="center" prop="awardCertificate" />
      <el-table-column label="爱好" align="center" prop="hobby" />
      <el-table-column label="自我评价" align="center" prop="selfEvaluation" />
      <el-table-column label="发展期望" align="center" prop="developmentExpectation" />
      <el-table-column label="业务状态" align="center" prop="businessStatus" />
      <el-table-column label="申请人" align="center" prop="applyUserName" />
      <el-table-column label="是否使用模板" align="center" prop="typeStatus" />
      <el-table-column label="审批人姓名(多个）" align="center" prop="approverName" />
      <el-table-column label="抄送人姓名(多个）" align="center" prop="copyerName" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['module:oaEntry:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['module:oaEntry:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改入职申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="auto" append-to-body>
      <el-form ref="form" :inline="true"  :model="form" :rules="rules" label-width="100px">

        <el-form-item label="公司/部门" prop="company">
<!--          <el-input v-model="form.company" placeholder="请输入公司" />-->
          <el-cascader
            v-model="value"
            :options="deptlist"
            :props="optionsProp"
            size="medium "
            @change="handleChange"></el-cascader>
        </el-form-item>
<!--        <el-form-item label="部门" prop="deptName">-->
<!--          <el-input v-model="form.deptName" placeholder="请输入部门" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="部门id" prop="deptId">-->
<!--          <el-input v-model="form.deptId" placeholder="请输入部门id" />-->
<!--        </el-form-item>-->
        <el-form-item label="职级" prop="rankId">
<!--          <el-input v-model="form.rankName" placeholder="请输入职级" />-->
          <el-select @change="changepost" v-model="form.rankId" placeholder="请选择">
            <el-option
              v-for="item in postlist"
              :key="item.postId"
              :label="item.postName"
              :value="item.postId"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="岗位" prop="post">
<!--          <el-input v-model="form.post" placeholder="请输入岗位" />-->
          <el-select
            @change="changepostinfo"
            v-model="form.post"
            :multiple="false"
            filterable
            remote
            reserve-keyword
            placeholder="请填写岗位"
            :remote-method="getpostinfolist"
            :loading="loading">
            <el-option
              v-for="item in postinfolist"
              :key="item.id"
              :label="item.postName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="姓名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入姓名" >
            <template slot="append">
              <el-button type="primary" @click="openusername(0)">
                请输入姓名
              </el-button>
            </template>
          </el-input>

        </el-form-item>
        <el-form-item label="生肖" prop="animalSign">
          <el-input v-model="form.animalSign" placeholder="请输入生肖" />
        </el-form-item>
        <el-form-item label="手机" prop="phoneNum">
          <el-input v-model="form.phoneNum" placeholder="请输入手机" />
        </el-form-item>
        <el-form-item label="身份证" prop="identification">
          <el-input v-model="form.identification" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday">
          <el-date-picker clearable
            v-model="form.birthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="身高/cm" prop="height">
          <el-input v-model="form.height" placeholder="请输入身高" />
        </el-form-item>
        <el-form-item label="体重/kg" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入体重" />
        </el-form-item>
        <el-form-item label="健康情况" prop="health">
<!--          <el-input v-model="form.health" placeholder="请输入健康情况" />-->
          <el-select v-model="form.health" placeholder="请选择">
            <el-option
              v-for="item in healthoptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="实习薪资" prop="internshipSalary">
          <el-input v-model="form.internshipSalary" placeholder="请输入实习薪资" />
        </el-form-item>
        <el-form-item label="试用时间/月" prop="probationTime">
          <el-input v-model="form.probationTime" placeholder="请输入试用时间" />
        </el-form-item>
        <el-form-item label="试用期工资" prop="probationSalary">
          <el-input v-model="form.probationSalary" placeholder="请输入试用期工资" />
        </el-form-item>
        <el-form-item label="转正后工资" prop="positiveSalary">
          <el-input v-model="form.positiveSalary" placeholder="请输入转正后工资" />
        </el-form-item>
        <el-form-item label="入职日期" prop="entryDate">
          <el-date-picker clearable
            v-model="form.entryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="籍贯" prop="nativePlace">
          <el-input v-model="form.nativePlace" placeholder="请输入籍贯" />
        </el-form-item>
        <el-form-item label="民族" prop="nation">
          <el-input v-model="form.nation" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="学历" prop="educational">
<!--          <el-input v-model="form.educational" placeholder="请输入学历" />-->
          <el-select v-model="form.educational" placeholder="请选择">
            <el-option
              v-for="item in educationaloptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开户行" prop="bankDeposit">
          <el-input v-model="form.bankDeposit" placeholder="请输入开户行" />
        </el-form-item>
        <el-form-item label="银行账号" prop="bankAccountNumber">
          <el-input v-model="form.bankAccountNumber" placeholder="请输入银行账号" />
        </el-form-item>
        <el-form-item label="现住址" prop="presentAddress">
          <el-input v-model="form.presentAddress" placeholder="请输入现住址" />
        </el-form-item>
        <el-form-item label="紧急联系人" prop="emergencyContact">
          <el-input v-model="form.emergencyContact" placeholder="请输入紧急联系人" />
        </el-form-item>
        <el-form-item label="所属关系" prop="ownership">
          <el-input v-model="form.ownership" placeholder="请输入所属关系" />
        </el-form-item>
        <el-form-item label="手机" prop="emergencyPhone">
          <el-input v-model="form.emergencyPhone" placeholder="请输入手机" />
        </el-form-item>

        <el-form-item label="劳动合同签约时间" prop="laborContractSigningTime">
          <el-date-picker clearable
            v-model="form.laborContractSigningTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择劳动合同签约时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="劳动合同到期时间" prop="laborContractExpirationTime">
          <el-date-picker clearable
            v-model="form.laborContractExpirationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择劳动合同到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="技能" prop="skill">
          <el-input v-model="form.skill" placeholder="请输入技能" />
        </el-form-item>
        <el-form-item label="爱好" prop="hobby">
          <el-input v-model="form.hobby" placeholder="请输入爱好" />
        </el-form-item>
        <el-form-item label="购买商业保险" prop="commercialInsurance">
          <!--          <el-input v-model="form.commercialInsurance" placeholder="请输入商业保险" />-->
          <el-radio  v-model="form.commercialInsurance" label="是">是</el-radio>
          <el-radio  v-model="form.commercialInsurance" label="否">否</el-radio>
        </el-form-item>
        <el-form-item label="奖励证书" prop="awardCertificate">
<!--          <el-input v-model="form.awardCertificate" placeholder="请输入奖励证书" />-->
          <imgUpload v-model="form.awardCertificate"></imgUpload>
        </el-form-item>

        <el-form-item label="自我评价" prop="selfEvaluation">
          <el-input v-model="form.selfEvaluation" placeholder="请输入自我评价" />
        </el-form-item>
        <el-form-item label="发展期望" prop="developmentExpectation">
          <el-input v-model="form.developmentExpectation" placeholder="请输入发展期望" />
        </el-form-item>

        <el-form-item label="申请人" prop="applyUserName">
          <el-input v-model="form.applyUserName" placeholder="请输入申请人" />
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否使用流程模板" prop="typeStatus">
          <el-select v-model="form.typeStatus" placeholder="请选择"   @change="changeValue">
            <el-option

              v-for="item in ynOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <!--自定义-->
        <div v-if="showApproval3">
          <div style="margin-left: 30px">
            <span>请选择审批人</span>
            <el-select @change="changeuseroptions" v-model="value1" multiple placeholder="请选择">
              <el-option
                v-for="item in userlistoptions"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId">
              </el-option>
            </el-select>
<!--            <el-input v-model="approver.userName" style="width: 300px">-->
<!--              <template slot="append">-->
<!--                <el-button type="primary"  @click="openUser(1)">-->
<!--                  选择审批人-->
<!--                </el-button>-->
<!--              </template>-->
<!--            </el-input>-->
          </div>
          <div style="margin-left: 30px;margin-top: 10px">
            <span style="margin-right: 5px">请选择抄送人</span>
            <el-input v-model="copyer.userName" style="width: 300px">
              <template slot="append">
                <el-button type="primary"  @click="openUser(2)">
                  选择抄送人
                </el-button>
              </template>
            </el-input>
          </div>
        </div>
        <el-divider content-position="center">工作经验信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddOaEntryWorkExperience">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteOaEntryWorkExperience">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="oaEntryWorkExperienceList" :row-class-name="rowOaEntryWorkExperienceIndex" @selection-change="handleOaEntryWorkExperienceSelectionChange" ref="oaEntryWorkExperience">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="开始年月" prop="startDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.startDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择开始年月" />
            </template>
          </el-table-column>
          <el-table-column label="结束年月" prop="endDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.endDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择结束年月" />
            </template>
          </el-table-column>
          <el-table-column label="工作单位" prop="company" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.company" placeholder="请输入工作单位" />
            </template>
          </el-table-column>
          <el-table-column label="职位" prop="post" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.post" placeholder="请输入职位" />
            </template>
          </el-table-column>
          <el-table-column label="离职原因" prop="resignationReason" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.resignationReason" placeholder="请输入离职原因" />
            </template>
          </el-table-column>
        </el-table>
        <el-divider content-position="center">教育经历信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddOaEntryEducationExperience">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteOaEntryEducationExperience">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="oaEntryEducationExperienceList" :row-class-name="rowOaEntryEducationExperienceIndex" @selection-change="handleOaEntryEducationExperienceSelectionChange" ref="oaEntryEducationExperience">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="开始年月" prop="startDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.startDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择开始年月" />
            </template>
          </el-table-column>
          <el-table-column label="结束年月" prop="endDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.endDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择结束年月" />
            </template>
          </el-table-column>
          <el-table-column label="学校" prop="school" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.school" placeholder="请输入学校" />
            </template>
          </el-table-column>
          <el-table-column label="专业" prop="profession" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.profession" placeholder="请输入专业" />
            </template>
          </el-table-column>
          <el-table-column label="技能" prop="skill" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.skill" placeholder="请输入技能" />
            </template>
          </el-table-column>
        </el-table>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <import-user ref="user" @showUser="showUser"></import-user>
  </div>
</template>

<script>
import { listOaEntry, getOaEntry, delOaEntry, addOaEntry, updateOaEntry } from "@/api/module/oaEntry";
import {deptTreeSelect} from "@/api/system/user";
import {listPost} from "@/api/system/post"
import {listPostInfo} from "@/api/module/postInfo"
import {getDicts} from "@/api/system/dict/data.js"
import imgUpload from '@/components/ImageUpload'
import log from "@/views/monitor/job/log";
import importUser from '@/views/dialog/user.vue';
import {getUserProfile,getuserList,getuserrank} from '@/api/system/user';
//公司部门
export default {
  name: "OaEntry",
  components:{imgUpload,importUser},
  data() {
    var validatePhone = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入电话号码'))
      }
      if (value.length !== 11) {
        callback(new Error('请输入正确电话号码'))
      }
      if (value.length !== 11) {
        callback(new Error('请输入正确电话号码'))
      }
      // 验证电话号码手机号码，包含至今所有号段? ?
      var ab = /^[1][3|4|5|6|7|8|9][0-9]{9}$/
      if (ab.test(value) === false) {
        callback(new Error('请输入正确电话号码'))
      }
      callback()
    }
    //自定义校验定义方法
    var identity = (rule, value, callback) => {
      const reg = /^[1-8]\d{5}(18|19|20)\d{2}(0[1-9]|10|11|12)(0[1-9]|[1-2][0-9]|30|31)\d{3}[0-9Xx]$/
      if (!reg.test(value)) {
        return callback(new Error('请输入正确的身份证号'));
      } else {
        callback()
      }
    }
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedOaEntryWorkExperience: [],
      // 子表选中数据
      checkedOaEntryEducationExperience: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入职申请表格数据
      oaEntryList: [],
      // 工作经验表格数据
      oaEntryWorkExperienceList: [],
      // 教育培训经历表格数据
      oaEntryEducationExperienceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serialNum: null,
        company: null,
        deptName: null,
        deptId: null,
        rankName: null,
        rankId: null,
        post: null,
        postId: null,
        type: null,
        userName: null,
        userId: null,
        animalSign: null,
        sex: null,
        phoneNum: null,
        identification: null,
        birthday: null,
        age: null,
        height: null,
        weight: null,
        health: null,
        internshipSalary: null,
        probationTime: null,
        probationSalary: null,
        positiveSalary: null,
        entryDate: null,
        nativePlace: null,
        nation: null,
        educational: null,
        politicalStatus: null,
        maritalStatus: null,
        bankDeposit: null,
        bankAccountNumber: null,
        presentAddress: null,
        emergencyContact: null,
        ownership: null,
        emergencyPhone: null,
        commercialInsurance: null,
        laborContractSigningTime: null,
        laborContractExpirationTime: null,
        skill: null,
        awardCertificate: null,
        hobby: null,
        selfEvaluation: null,
        developmentExpectation: null,
        businessStatus: null,
        applyUserId: null,
        applyUserName: null,
        typeStatus: null,
        approver: null,
        approverName: null,
        copyerId: null,
        copyerName: null,
      },
      // 表单参数
      form: {
        company:'',
        applyUserId:'',
        applyUserName:'',
        userName:'',

      },
      // 表单校验
      rules: {
           // company:[{required:true,message:'请选择公司部门',trigger:['blur','change']}],
           // rankId:[{required:true,message:'请选择职级',trigger:['blur','change']}],
           // post:[{required:true,message:'请选择岗位',trigger:['blur','change']}],
           userName:[{required:true,message:'请输入申请人',trigger:['blur','change']}],
           phoneNum:[{required:true,message:'请输入电话',trigger:'blur'},{ validator: validatePhone, trigger: ['blur','change'] }],
           identification:[{required: true, validator: identity, trigger: ['blur','change']}],
           educational:[{required:true,message:'请选择学历',trigger:['blur','change']}],
           bankDeposit:[{required:true,message:'请填写开户行',trigger:['blur','change']}],
           bankAccountNumber:[{required:true,message:'请填写银行账号',trigger:['blur','change']}],
           presentAddress:[{required:true,message:'请填写居住地址',trigger:['blur','change']}],
           emergencyContact:[{required:true,message:'请填写紧急联系人',trigger:['blur','change']}],
           emergencyPhone:[{required:true,message:'请填写紧急联系电话',trigger:['blur','change']},{ validator: validatePhone, trigger: ['blur','change'] }],
      },
    deptlist:[],
      value:[],
      optionsProp:{value:'id',label:'label',children:'children'},
      postlist:[],//职级
      postinfolist:[],//岗位
      healthoptions:[],
      educationaloptions:[],
      ynOptions:[],//是否
      showApproval3:false,
      approver:{},//自定义审批人
      copyer:{},
      value1:[],
      userlistoptions:[]
    };
  },
  created() {

    this.getList();
    this.getdeptlist()//部门
    this.getpostlist()//职级
    this.getpostinfolist()//岗位
    this.gethealthoptions()//健康情况
    this.geteducationaloptions()//学历
    this.getYesNo()
    this.getrankuser()
  },
  methods: {
    // 查询主管级别用户
    getrankuser(){
      getuserrank({rank:"主管",pageSize:1000}).then(res=>{
        this.userlistoptions=res.rows
      })
    },
    changeuseroptions(val){
      this.form.approverName=null
      val.forEach(ids=>{
        this.userlistoptions.forEach(item=>{
          if(ids==item.userId){
            if(this.form.approverName==null){
              this.form.approverName=item.userName
            }else {
              this.form.approverName= this.form.approverName+','+item.userName
            }
          }
        })
      })
    },
    //获取部门列表
    async getdeptlist(){
    let res=await deptTreeSelect()
      this.deptlist=res.data
    },
    handleChange(value){
      console.log(value)

    /*  this.form.company*/
     this.form.deptId=value[2]
       this.getlcompany(this.deptlist,value[1],this.form.company)
      this.getdeptlabel(this.deptlist,value[2],this.form.company)
      console.log(this.form,909090)
    },
    //遍历数组
    getlcompany(arr,value,label){
      var newlabel=''
      for(var i=0;i<arr.length;i++){
        if(arr[i].id==value){
          newlabel=arr[i].label
        this.form.company=arr[i].label

        }
        if(arr[i].children){
          this.getlcompany(arr[i].children,value,label)
        }

      }


    },
    getdeptlabel(arr,value,label){
      arr.forEach(item=>{
        if(item.id==value){
          label=item.label
       this.form.deptName=item.label
          return
        }

        if(item.children){
          this.getdeptlabel(item.children,value,label)
        }
      })
    },
    //获取职级
    getpostlist(){
      listPost().then(res=>{
        this.postlist=res.rows
      })
    },
    changepost(val){
       this.postlist.forEach(item=>{
         if(item.postId==val){
           this.form.rankName=item.postName

         }
       })
    },
    //获取岗位
    getpostinfolist(query){
      listPostInfo({postName:query}).then(res=>{
        this.postinfolist=res.rows
      })

    },
    changepostinfo(val){
    this.form.postId=val
      this.postinfolist.forEach(item=>{
        if(item.id==val){
          this.form.post=item.postName
        }
      })

    },
    //健康情况、
    gethealthoptions(){
      getDicts('kang').then(res=>{
        this.healthoptions=res.data
      })
    },
    //学历
    geteducationaloptions(){
      getDicts('education').then(res=>{
        this.educationaloptions=res.data
      })
    },
    //是或否
    getYesNo(){
      getDicts('yesorno').then(res=>{
        this.ynOptions=res.data
      })
    },
    changeValue(val){
      if(val==1){
        this.showApproval3=true
      }
    },
    //打开用户
    openUser(val){
      this.$refs.user.show(val,1)
    },
    openusername(val){
      this.$refs.user.show(val)
    },
    showUser(data){

      if(data.type=='0'){
        //自定义类型赋值
        this.form.userId=data.userId
        this.form.userName=data.userName
      }
      if(data.type=='1'){
        this.approver=data

        //自定义类型赋值
        this.form.approver=data.userId
        this.form.approverName=data.userName
      }
      if(data.type=='2'){
        this.copyer=data
        this.form.copyerId=data.userId
        this.form.copyerName=data.userName
      }


    },


    /** 查询入职申请列表 */
    getList() {
      this.loading = true;
      listOaEntry(this.queryParams).then(response => {
        this.oaEntryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serialNum: null,
        company: null,
        deptName: null,
        deptId: null,
        rankName: null,
        rankId: null,
        post: null,
        postId: null,
        type: null,
        userName: null,
        userId: null,
        animalSign: null,
        sex: null,
        phoneNum: null,
        identification: null,
        birthday: null,
        age: null,
        height: null,
        weight: null,
        health: null,
        internshipSalary: null,
        probationTime: null,
        probationSalary: null,
        positiveSalary: null,
        entryDate: null,
        nativePlace: null,
        nation: null,
        educational: null,
        politicalStatus: null,
        maritalStatus: null,
        bankDeposit: null,
        bankAccountNumber: null,
        presentAddress: null,
        emergencyContact: null,
        ownership: null,
        emergencyPhone: null,
        commercialInsurance: null,
        laborContractSigningTime: null,
        laborContractExpirationTime: null,
        skill: null,
        awardCertificate: null,
        hobby: null,
        selfEvaluation: null,
        developmentExpectation: null,
        businessStatus: null,
        applyUserId: null,
        applyUserName: null,
        typeStatus: null,
        approver: null,
        approverName: null,
        copyerId: null,
        copyerName: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.oaEntryWorkExperienceList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form={

        applyUserId:this.$store.getters.id,
        applyUserName:this.$store.getters.name,
        userName:this.$store.getters.name,
        userId:this.$store.getters.id,
      }
      this.open = true;
      this.title = "添加入职申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOaEntry(id).then(response => {
        this.form = response.data;
         this.value=[100]
         this.getcomponylist(this.form.company,this.deptlist)
        this.value.push(this.form.deptId)
        this.oaEntryWorkExperienceList = response.data.oaEntryWorkExperienceList;
        this.oaEntryEducationExperienceList = response.data.oaEntryEducationExperienceList;
        this.open = true;
        this.title = "修改入职申请";
      });
    },
    // 处理回显数据
    getcomponylist(val,arry){
      arry.forEach(item=>{
        if(item.label==val){
          this.value.push(Number(item.id))
          console.log(item,'iii')
          return
        }
        if(item.children){
          console.log(2121)
          this.getcomponylist(val,item.children)
        }
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.form.approver=this.value1.join(',')
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.oaEntryWorkExperienceList = this.oaEntryWorkExperienceList;
          this.form.oaEntryEducationExperienceList = this.oaEntryEducationExperienceList;
          if (this.form.id != null) {
            updateOaEntry(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOaEntry(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除入职申请编号为"' + ids + '"的数据项？').then(function() {
        return delOaEntry(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 工作经验序号 */
    rowOaEntryWorkExperienceIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 教育经验序号 */
    rowOaEntryEducationExperienceIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 工作经验添加按钮操作 */
    handleAddOaEntryWorkExperience() {
      let obj = {};
      obj.startDate = "";
      obj.endDate = "";
      obj.company = "";
      obj.post = "";
      obj.resignationReason = "";
      obj.remark = "";
      this.oaEntryWorkExperienceList.push(obj);
    },
    /** 教育经历添加按钮操作 */
    handleAddOaEntryEducationExperience() {
      let obj = {};
      obj.startDate = "";
      obj.endDate = "";
      obj.school = "";
      obj.profession = "";
      obj.skill = "";
      obj.remark = "";
      this.oaEntryEducationExperienceList.push(obj);
    },
    /** 工作经验删除按钮操作 */
    handleDeleteOaEntryWorkExperience() {
      if (this.checkedOaEntryWorkExperience.length == 0) {
        this.$modal.msgError("请先选择要删除的工作经验数据");
      } else {
        const oaEntryWorkExperienceList = this.oaEntryWorkExperienceList;
        const checkedOaEntryWorkExperience = this.checkedOaEntryWorkExperience;
        this.oaEntryWorkExperienceList = oaEntryWorkExperienceList.filter(function(item) {
          return checkedOaEntryWorkExperience.indexOf(item.index) == -1
        });
      }
    },
    /** 工作经验删除按钮操作 */
    handleDeleteOaEntryEducationExperience() {
      if (this.checkedOaEntryEducationExperience.length == 0) {
        this.$modal.msgError("请先选择要删除的教育经验数据");
      } else {
        const oaEntryEducationExperienceList = this.oaEntryEducationExperienceList;
        const checkedOaEntryEducationExperience = this.checkedOaEntryEducationExperience;
        this.oaEntryEducationExperienceList = oaEntryEducationExperienceList.filter(function(item) {
          return checkedOaEntryEducationExperience.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleOaEntryWorkExperienceSelectionChange(selection) {
      this.checkedOaEntryWorkExperience = selection.map(item => item.index)
    },
    /** 复选框选中数据 */
    handleOaEntryEducationExperienceSelectionChange(selection) {
      this.checkedOaEntryEducationExperience = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('module/oaEntry/export', {
        ...this.queryParams
      }, `oaEntry_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
